package com.isunland.managesystem.base;

import android.content.Context;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;
import com.isunland.managesystem.R;
import java.util.List;

/**
 * 对象功能:
 * 开发公司: 北京信普达系统工程有限公司
 * 开发人员: HuXiaoDan
 * 创建时间: 2017/1/13 09:45
 */
public abstract class BaseShadowListAdapter<T> extends ArrayAdapter<T> {

  /**
   * ViewHolder class for layout.<br />
   * <br />
   * Auto-created on 2017-01-13 10:06:27 by Android Layout Finder
   * (http://www.buzzingandroid.com/tools/android-layout-finder)
   */
  protected static class ViewHolder {
    public final LinearLayout mHolderRootView;
    public final LinearLayout mHolderOneVg;
    public final TextView mContentOneTv;
    public final TextView mContentStatusTv;
    public final LinearLayout mHolderTwoVg;
    public final TextView mTitleTwoTv;
    public final TextView mContentTwoTv;
    public final TextView mContentThreeTv;
    public final TextView mContentFourTv;
    public final TextView mContentFiveTv;
    public final TextView mContentSevenTv;
    public final TextView mContentSixTv;
    public final TextView mContentEightTv;

    public final LinearLayout mHolderShadowVg;
    public final TextView mPersonNameTv;
    public final TextView mPersonDataTv;
    public final TextView mTypeTv;

    private ViewHolder(LinearLayout rootView, LinearLayout ll_holderOne_simpleList,
        TextView tv_contentOne_simpleList, TextView ll_planStatus,
        LinearLayout ll_holderTwo_simpleList, TextView tv_TitleTwo_simpleList,
        TextView tv_contentTwo_simpleList, TextView tv_contentThree_simpleList,
        TextView tv_contentFour_simpleList, TextView tv_contentFive_simpleList,
        TextView tv_contentSix_simpleList, TextView tv_contentSeven_simpleList,
        TextView tv_contentEight_simpleList, LinearLayout ll_holderThree_simpleList,
        TextView tv_person_name, TextView tv_person_data, TextView tv_type) {
      this.mHolderRootView = rootView;
      this.mHolderOneVg = ll_holderOne_simpleList;
      this.mContentOneTv = tv_contentOne_simpleList;
      this.mContentStatusTv = ll_planStatus;
      this.mHolderTwoVg = ll_holderTwo_simpleList;
      this.mTitleTwoTv = tv_TitleTwo_simpleList;
      this.mContentTwoTv = tv_contentTwo_simpleList;
      this.mContentThreeTv = tv_contentThree_simpleList;
      this.mContentFourTv = tv_contentFour_simpleList;
      this.mContentFiveTv = tv_contentFive_simpleList;
      this.mContentSixTv = tv_contentSix_simpleList;
      this.mContentSevenTv = tv_contentSeven_simpleList;
      this.mContentEightTv = tv_contentEight_simpleList;
      this.mHolderShadowVg = ll_holderThree_simpleList;
      this.mPersonNameTv = tv_person_name;
      this.mPersonDataTv = tv_person_data;
      this.mTypeTv = tv_type;
    }

    public static ViewHolder create(LinearLayout rootView) {
      LinearLayout ll_holderOne_simpleList =
          (LinearLayout) rootView.findViewById(R.id.ll_holderOne_simpleList);
      TextView tv_contentOne_simpleList =
          (TextView) rootView.findViewById(R.id.tv_contentOne_simpleList);
      TextView ll_planStatus = (TextView) rootView.findViewById(R.id.ll_planStatus);
      LinearLayout ll_holderTwo_simpleList =
          (LinearLayout) rootView.findViewById(R.id.ll_holderTwo_simpleList);
      TextView tv_TitleTwo_simpleList =
          (TextView) rootView.findViewById(R.id.tv_TitleTwo_simpleList);
      TextView tv_contentTwo_simpleList =
          (TextView) rootView.findViewById(R.id.tv_contentTwo_simpleList);
      TextView tv_contentThree_simpleList =
          (TextView) rootView.findViewById(R.id.tv_contentThree_simpleList);
      TextView tv_contentFour_simpleList =
          (TextView) rootView.findViewById(R.id.tv_contentFour_simpleList);
      TextView tv_contentFive_simpleList =
          (TextView) rootView.findViewById(R.id.tv_contentFive_simpleList);
      TextView tv_contentSix_simpleList =
          (TextView) rootView.findViewById(R.id.tv_contentSix_simpleList);
      TextView tv_contentSeven_simpleList =
          (TextView) rootView.findViewById(R.id.tv_contentSeven_simpleList);
      TextView tv_contentEight_simpleList =
          (TextView) rootView.findViewById(R.id.tv_contentEight_simpleList);
      LinearLayout ll_holderThree_simpleList =
          (LinearLayout) rootView.findViewById(R.id.ll_holderThree_simpleList);
      TextView tv_person_name = (TextView) rootView.findViewById(R.id.tv_person_name);
      TextView tv_person_data = (TextView) rootView.findViewById(R.id.tv_person_data);
      TextView tv_type = (TextView) rootView.findViewById(R.id.tv_type);
      return new ViewHolder(rootView, ll_holderOne_simpleList, tv_contentOne_simpleList,
          ll_planStatus, ll_holderTwo_simpleList, tv_TitleTwo_simpleList, tv_contentTwo_simpleList,
          tv_contentThree_simpleList, tv_contentFour_simpleList, tv_contentFive_simpleList,
          tv_contentSix_simpleList, tv_contentSeven_simpleList, tv_contentEight_simpleList,
          ll_holderThree_simpleList, tv_person_name, tv_person_data, tv_type);
    }
  }

  @Override public View getView(int position, View convertView, ViewGroup parent) {
    final ViewHolder vh;
    if (convertView == null) {
      View view = mInflater.inflate(R.layout.adapter_shadow_item, parent, false);
      vh = ViewHolder.create((LinearLayout) view);
      view.setTag(vh);
    } else {
      vh = (ViewHolder) convertView.getTag();
    }
    T item = getItem(position);
    bindData(position, vh, item);

    //该通用界面默认有四行,根据行数不同,控制显示和隐藏
    String titleOneStr = vh.mContentOneTv.getText().toString().trim();
    String titleTwoStr = vh.mTitleTwoTv.getText().toString().trim();
    String contentTwoStr = vh.mContentTwoTv.getText().toString().trim();
    String titleThreeStr = vh.mContentThreeTv.getText().toString().trim();
    String titleFourStr = vh.mContentFourTv.getText().toString().trim();
    String titleFiveStr = vh.mContentFiveTv.getText().toString().trim();
    String titleSixStr = vh.mContentSixTv.getText().toString().trim();
    String titleSevenStr = vh.mContentSevenTv.getText().toString().trim();
    String titleEightStr = vh.mContentEightTv.getText().toString().trim();
    String planStatus = vh.mContentStatusTv.getText().toString().trim();
    String type = vh.mTypeTv.getText().toString().trim();
    String personName = vh.mPersonNameTv.getText().toString().trim();
    String personData = vh.mPersonDataTv.getText().toString().trim();

    if (TextUtils.isEmpty(titleOneStr) && TextUtils.isEmpty(planStatus)) {
      vh.mHolderOneVg.setVisibility(View.GONE);
    } else {
      vh.mHolderOneVg.setVisibility(View.VISIBLE);
    }
    if (TextUtils.isEmpty(planStatus)) {
      vh.mContentStatusTv.setVisibility(View.GONE);
    } else {
      vh.mContentStatusTv.setVisibility(View.VISIBLE);
    }
    if (TextUtils.isEmpty(titleTwoStr) && TextUtils.isEmpty(contentTwoStr)) {
      vh.mHolderTwoVg.setVisibility(View.GONE);
    } else {
      vh.mHolderTwoVg.setVisibility(View.VISIBLE);
      if (TextUtils.isEmpty(titleTwoStr)) {
        vh.mTitleTwoTv.setVisibility(View.GONE);
      } else {
        vh.mTitleTwoTv.setVisibility(View.VISIBLE);
      }
      if (TextUtils.isEmpty(contentTwoStr)) {
        vh.mContentTwoTv.setVisibility(View.GONE);
      } else {
        vh.mContentTwoTv.setVisibility(View.VISIBLE);
      }
    }
    if (TextUtils.isEmpty(titleThreeStr)) {
      vh.mContentThreeTv.setVisibility(View.GONE);
    } else {
      vh.mContentThreeTv.setVisibility(View.VISIBLE);
    }
    if (TextUtils.isEmpty(titleFourStr)) {
      vh.mContentFourTv.setVisibility(View.GONE);
    } else {
      vh.mContentFourTv.setVisibility(View.VISIBLE);
    }

    if (TextUtils.isEmpty(titleFiveStr)) {
      vh.mContentFiveTv.setVisibility(View.GONE);
    } else {
      vh.mContentFiveTv.setVisibility(View.VISIBLE);
    }
    if (TextUtils.isEmpty(titleSixStr)) {
      vh.mContentSixTv.setVisibility(View.GONE);
    } else {
      vh.mContentSixTv.setVisibility(View.VISIBLE);
    }
    if (TextUtils.isEmpty(titleSevenStr)) {
      vh.mContentSevenTv.setVisibility(View.GONE);
    } else {
      vh.mContentSevenTv.setVisibility(View.VISIBLE);
    }
    if (TextUtils.isEmpty(titleEightStr)) {
      vh.mContentSevenTv.setVisibility(View.GONE);
    } else {
      vh.mContentSevenTv.setVisibility(View.VISIBLE);
    }
    if (TextUtils.isEmpty(titleEightStr)) {
      vh.mContentEightTv.setVisibility(View.GONE);
    } else {
      vh.mContentEightTv.setVisibility(View.VISIBLE);
    }
    if (TextUtils.isEmpty(type) && TextUtils.isEmpty(personName) && TextUtils.isEmpty(personData)) {
      vh.mHolderShadowVg.setVisibility(View.GONE);
    } else {
      vh.mHolderShadowVg.setVisibility(View.VISIBLE);
      if (TextUtils.isEmpty(type)) {
        vh.mTypeTv.setVisibility(View.GONE);
      } else {
        vh.mTypeTv.setVisibility(View.VISIBLE);
      }
      if (TextUtils.isEmpty(personName)) {
        vh.mPersonNameTv.setVisibility(View.GONE);
      } else {
        vh.mPersonNameTv.setVisibility(View.VISIBLE);
      }
      if (TextUtils.isEmpty(personData)) {
        vh.mPersonDataTv.setVisibility(View.GONE);
      } else {
        vh.mPersonDataTv.setVisibility(View.VISIBLE);
      }
    }

    return vh.mHolderRootView;
  }

  /**
   * @param position 位置
   * @param vh 界面
   * @param item 数据
   * @return void
   * @Title: bindData
   * @Description: 绑定数据  在绑定数据时必须同时绑定标题和内容.
   */
  public abstract void bindData(int position, final ViewHolder vh, T item);

  private LayoutInflater mInflater;

  // Constructors
  public BaseShadowListAdapter(Context context, List<T> objects) {
    super(context, 0, objects);
    this.mInflater = LayoutInflater.from(context);
  }

  public BaseShadowListAdapter(Context context, T[] objects) {
    super(context, 0, objects);
    this.mInflater = LayoutInflater.from(context);
  }
}
